package note.analysis;
/*
    获取注解的属性值
 */
import java.lang.reflect.Method;

public class TextDemo {
    public static void main(String[] args) throws NoSuchMethodException {
        //获取People类的字节码文件
        Class<People> p = People.class;
        //获取People类的注解，返回一个布尔值
        boolean annotationPresent = p.isAnnotationPresent(Book.class);
        if(annotationPresent) {
            //通过People类的字节码对象调用getAnnotation方法，参数为注解的字节码
            Book annotation = p.getAnnotation(Book.class);
            //通过注解的字节码对象获取属性值
            String[] author = annotation.author();
            for (String s : author) {
                System.out.println(s);
            }
        }
        Method show = p.getMethod("show");
        boolean annotationPresent1 = show.isAnnotationPresent(Book.class);
        if(annotationPresent) {
            Book annotation = show.getAnnotation(Book.class);
            int age = annotation.age();
            System.out.println(age);
        }
    }
}
